package argo.hot100.arr;

public class FirstMissingPositive {

    public int firstMissingPositive(int[] nums) {


        for (int i = 0; i < nums.length; i++) {
            while (nums[i] < nums.length && nums[i] > 0 && nums[nums[i] - 1] != nums[i]) {
                int tmp = nums[nums[i] - 1];
                nums[nums[i] - 1] = nums[i];
                nums[i] = tmp;
            }
        }


        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != i + 1) {
                return i + 1;
            }
        }

        return nums.length + 1;


    }

    public static void main(String[] args) {
        System.out.println(new FirstMissingPositive().firstMissingPositive(new int[]{-1, 4, 2, 1, 9, 10}));
    }


}
